#!/bin/bash
node_list="$1"
pw_str="p@ssword"
fs_version="3.1.2"
source_client="/home/hzz/git_worktree/meta_quota_local/client_module/"
remote_client="/opt/orcafs/src/client/client_module_${fs_version}"
ko_path="/lib/modules/4.18.0-240.el8.x86_64/updates/fs/orcafs_autobuild/"
#ko_path="/lib/modules/4.18.0-240.el8.x86_64/updates/fs/orcafs/"

function update_client()
{
    # update orcafs-api for all nodes
    current=$(date "+%Y%m%d%H%M%S")
    for node in "${node_list[@]}"; do
        echo -------------"${node}"-----------
        sshpass -p $pw_str rsync -av --delete ${source_client} root@192.168."${node}":${remote_client}
        sshpass -p $pw_str ssh root@192.168."${node}" <<EOF &
systemctl stop orcafs-client
umount /mnt/orcafs
umount /mnt/default
rmmod orcafs
make -j8 -C ${remote_client}/build/ ORCAFS_VERSION=$current
ls -l  ${remote_client}/build/
mv ${remote_client}/build/orcafs.ko ${remote_client}/build/bk_orcafs.ko 
mv ${remote_client}/build/orcafs-unstripped.ko ${remote_client}/build/orcafs.ko
insmod ${remote_client}/build/orcafs.ko
/usr/bin/cp -f ${remote_client}/build/orcafs.ko ${ko_path}
systemctl start orcafs-client
EOF
    done
    wait
}

update_client
